<template>
    <div class="flexbox spacebetween">
        <ul>
            <li v-for="(item,index) in 6" :key="index" :class="['tdchip','cp0'+index]" @click="betnumFun(index)"></li>
        </ul>
        <div class="margintop">
            <div>
                <label for="quickBet"><input type="checkbox" id="quickBet" v-model="quickBetSel">快捷下注</label>
                <label for="betmoneyinp">金额<input type="text" id="betmoneyinp" v-model="betSum"></label>
            </div>
            <div class="flexbox spacebetween operationbtn">
                <input type="button" value="下注" @click="bottomPour" :disabled="betDisabled" :style="betDisabled?'color: palevioletred;':''" />
                <input type="button" value="重填" @click="resetFun" />
                <input type="button" value="清空" @click="clearbetmoneyFun" />
            </div>
            <p class="colorRed text-center">注：多次点击筹码，金额将累加！</p>
        </div>
    </div>
</template>

<script>
    import axios from 'axios'
    import {lotterytype} from '../../../../assets/js/lotterytype.js'
    export default {
        name: "Quickbet",
        props: {  //普通类型：String、Number、Boolean、Null    引用类型： Array、Object
            betdata: {   //   下注提交数据
                type: Object,
                required: true
            },
            contBetData: {  //连码  下注
                type: Object,
                required: true
            },
            noBet: {  //不可下注
                type: Boolean,
                required: true
            },
            openBet: {  //开奖  可下注
                type: Boolean,
                required: true
            },
        },
        data(){
            return{
                betSum: '',  //下注金额
                quickBetSel: false,  //快捷下注
                ratedata: {},  //实时赔率
                betconfirm: [],  //下注弹框确认内容
                contArr: ['任选二','选二连组','任选三','选三前组','任选四','任选五'],
                betDisabled: false,  //不可下注
            }
        },
        methods: {
            init(){
                // console.log(this.$route.query);
            },
            //快捷下注  和
            betnumFun(ind){

                let nums = 0;
                if(ind == 0){
                    nums = 10;
                }else if(ind == 1){
                    nums = 50;
                }else if(ind == 2){
                    nums = 100;
                }else if(ind == 3){
                    nums = 500;
                }else if(ind == 4){
                    nums = 1000;
                }else if(ind == 5){
                    nums = 5000;
                }

                if(!this.betSum){
                    this.betSum = 0;
                }else{
                    this.betSum = parseFloat(this.betSum);
                }
                this.betSum += nums;
                this.betSum = this.betSum.toString();
            },
            //下注
            bottomPour(){
                console.log(this.contBetData);
                var _this = this;

                //判断是否为连码
                //
                if((this.$route.query.id == 2) && this.$route.query.levelid == 18){   //六合彩  连码

                    if(_this.betSum != '' && _this.betSum != 0){

                        if(_this.contBetData.radioopt == 0){  //连码:二全中:$fn
                            _this.contBetFun('二全中');
                        }else if(_this.contBetData.radioopt == 1){  //连码:二中特:中二
                            _this.contBetFun('二中特');
                        }else if(_this.contBetData.radioopt == 2){  //连码:三全中:$fn
                            _this.contBetFun('三全中');
                        }else if(_this.contBetData.radioopt == 3){  //连码:三中二:中二
                            _this.contBetFun('三中二');
                        }else if(_this.contBetData.radioopt == 4){  //连码:特串:$fn
                            _this.contBetFun('特串');
                        }else if(_this.contBetData.radioopt == 5){  //连码:四全中:$fn
                            _this.contBetFun('四全中');
                        }else if(_this.contBetData.radioopt == 6){  //连码:选二连组:$fn
                            _this.contBetFun('选二连组');
                        }else if(_this.contBetData.radioopt == 7){  //连码:选三连组:$fn
                            _this.contBetFun('选三连组');
                        }else if(_this.contBetData.radioopt == 8){  //连码:选三前组:$fn
                            _this.contBetFun('选三前组');
                        }else if(_this.contBetData.radioopt == 9){  //连码:选四前组:$fn
                            _this.contBetFun('选四前组');
                        }
                    }else{
                        alert('请填写下注金额！');
                    }
                }else if((this.$route.query.id == 2) && (this.$route.query.levelid == 12 || this.$route.query.levelid == 15 || this.$route.query.levelid == 19)){   //六合彩  合肖、自选不中    过关

                    if(_this.betSum != '' && _this.betSum != 0){

                        if(_this.contBetData.radioopt == 0){  //
                            _this.contBetFun();
                        }

                    }else{
                        alert('请填写下注金额！');
                    }

                }else if(this.$route.query.id == 2 && this.$route.query.levelid == 16){  //六合彩    连肖

                    if(_this.betSum != '' && _this.betSum != 0){

                        if(_this.contBetData.radioopt == 0){  //二肖连中
                            _this.contBetFun('二肖连中');
                        }else if(_this.contBetData.radioopt == 1){  //三肖连中
                            _this.contBetFun('三肖连中');
                        }else if(_this.contBetData.radioopt == 2){  //四肖连中
                            _this.contBetFun('四肖连中');
                        }else if(_this.contBetData.radioopt == 3){  //五肖连中
                            _this.contBetFun('五肖连中');
                        }else if(_this.contBetData.radioopt == 4){  //二肖连不中
                            _this.contBetFun('二肖连不中');
                        }else if(_this.contBetData.radioopt == 5){  //三肖连不中
                            _this.contBetFun('三肖连不中');
                        }else if(_this.contBetData.radioopt == 6){  //四肖连不中
                            _this.contBetFun('四肖连不中');
                        }else if(_this.contBetData.radioopt == 7){  //五肖连不中
                            _this.contBetFun('五肖连不中');
                        }

                    }else{
                        alert('请填写下注金额！');
                    }

                }else if(this.$route.query.id == 2 && this.$route.query.levelid == 17){  //六合彩    连尾

                    if(_this.betSum != '' && _this.betSum != 0){

                        if(_this.contBetData.radioopt == 0){  //二尾连中
                            _this.contBetFun('二尾连中');
                        }else if(_this.contBetData.radioopt == 1){  //三尾连中
                            _this.contBetFun('三尾连中');
                        }else if(_this.contBetData.radioopt == 2){  //四尾连中
                            _this.contBetFun('四尾连中');
                        }else if(_this.contBetData.radioopt == 3){  //五尾连中
                            _this.contBetFun('五尾连中');
                        }else if(_this.contBetData.radioopt == 4){  //二尾连不中
                            _this.contBetFun('二尾连不中');
                        }else if(_this.contBetData.radioopt == 5){  //三尾连不中
                            _this.contBetFun('三尾连不中');
                        }else if(_this.contBetData.radioopt == 6){  //四尾连不中
                            _this.contBetFun('四尾连不中');
                        }else if(_this.contBetData.radioopt == 7){  //五尾连不中
                            _this.contBetFun('五尾连不中');
                        }

                    }else{
                        alert('请填写下注金额！');
                    }

                }else if((this.$route.query.id == 11 || this.$route.query.id == 12 || this.$route.query.id == 13) && this.$route.query.levelid == 3){   //山东11选5、广东11选5、江西11选5  连码
                    
                    if(_this.betSum != '' && _this.betSum != 0){

                        if(_this.contBetData.radioopt == 0){  //选号:任选二:$fn
                            _this.contBetFun('任选二');
                        }else if(_this.contBetData.radioopt == 1){  //选号:任选三:$fn
                            _this.contBetFun('任选三');
                        }else if(_this.contBetData.radioopt == 2){  //选号:任选四:$fn
                            _this.contBetFun('任选四');
                        }else if(_this.contBetData.radioopt == 3){  //选号:任选五:$fn
                            _this.contBetFun('任选五');
                        }else if(_this.contBetData.radioopt == 4){  //选号:任选六:$fn
                            _this.contBetFun('任选六');
                        }else if(_this.contBetData.radioopt == 5){  //选号:任选七:$fn
                            _this.contBetFun('任选七');
                        }else if(_this.contBetData.radioopt == 6){  //选号:任选八:$fn
                            _this.contBetFun('任选八');
                        }else if(_this.contBetData.radioopt == 7){  //选号:前二组选:$fn
                            _this.contBetFun('前二组选');
                        }else if(_this.contBetData.radioopt == 8){  //选号:前三组选:$fn
                            _this.contBetFun('前三组选');
                        }
                    }else{
                        alert('请填写下注金额！');
                    }
                }else if((this.$route.query.id == 11 || this.$route.query.id == 12 || this.$route.query.id == 13) && this.$route.query.levelid == 4){  //直码
                    
                    if(_this.betSum != '' && _this.betSum != 0){
                        if(_this.contBetData.radioopt == 0){  //选号:前二直选:$fn
                            _this.contBetFun('前二直选');
                        }else if(_this.contBetData.radioopt == 1){  //选号:前三直选:$fn
                            _this.contBetFun('前三直选');
                        }
                    }else{
                        alert('请填写下注金额！');
                    }

                }else if((this.$route.query.id == 14 || this.$route.query.id == 15) && this.$route.query.levelid == 11){   //广东快乐十分、重庆幸运农场  连码

                    if(_this.betSum != '' && _this.betSum != 0){

                        if(_this.contBetData.radioopt == 0){  //连码:任选二:$fn
                            _this.contBetFun('任选二');
                        }else if(_this.contBetData.radioopt == 1){  //连码:选二连组:$fn
                            _this.contBetFun('选二连组');
                        }else if(_this.contBetData.radioopt == 2){  //连码:任选三:$fn
                            _this.contBetFun('任选三');
                        }else if(_this.contBetData.radioopt == 3){  //连码:选三前组:$fn
                            _this.contBetFun('选三前组');
                        }else if(_this.contBetData.radioopt == 4){  //连码:任选四:$fn
                            _this.contBetFun('任选四');
                        }else if(_this.contBetData.radioopt == 5){  //连码:任选五:$fn
                            _this.contBetFun('任选五');
                        }
                    }else{
                        alert('请填写下注金额！');
                    }
                }else{
                    //两面盘、第几球、正码
                    if(JSON.stringify(this.betdata) != "{}"){
                        
                        this.params = lotterytype.apiParams(this.$route.query.id,this.$route.query.levelid);
                        if(this.$route.query.id == 2 && this.$route.query.levelid == 8){  //六合彩 正码特
                            
                            var url = '/api/game/listRate/'+ this.params.nowlottery + '/' + this.params.levellottery + this.betdata.items[0].item.substr(0,3) +'oa18';
                            var suburl = '/api/setting/rateItem/'+ this.params.nowlottery + '/' + this.params.levellottery + this.betdata.items[0].item.substr(0,3) +'oa18';
                        }else{
                            var url = '/api/game/listRate/'+ this.params.nowlottery + '/' + this.params.levellottery +'oa18';
                            var suburl = '/api/setting/rateItem/'+ this.params.nowlottery + '/' + this.params.levellottery +'oa18';
                        }
                        this.$httpGet(url).then(response => {
                        
                            if(response.status == 200){
                                _this.ratedata = response.data.rates;  //所有赔率

                                var txt = '';
                                var sum = 0;
                                for(var i = 0;i<_this.betdata.items.length;i++){
                                    sum += parseFloat(_this.betdata.items[i].value);
                                    _this.betconfirm.push({'item': _this.betdata.items[i].item,'rate': _this.ratedata[_this.betdata.items[i].item],'money': _this.betdata.items[i].value});
                                    txt += _this.betdata.items[i].item + '  @  ' + _this.ratedata[_this.betdata.items[i].item] + '  *  ￥' + _this.betdata.items[i].value +'\n';
                                    
                                }

                                var mymessage=confirm('共￥'+ sum +' / '+ _this.betdata.items.length +'笔，确认下注吗？\n\n下注明细如下：\n\n' + txt);
                                
                                if(mymessage==true){
                                    //下注
                                    this.$httpPost("/api/bet/bet",_this.betdata).then(response => {
                        
                                        console.log(response);
                                        //下注成功（发送   最新注单事件）
                                        if(response.status == 200){
                                            _this.$emit('betsuccess',response.data);
                                        }
                                    })
                                    
                                }

                                if(response.data.need){
                                    _this.$httpPost(suburl).then(response => {
                                    
                                        if(response.status == 200){
                                            
                                        }

                                    });
                                }
                            }

                        });
                        
                    }else{
                        alert('请填写下注金额！');
                    }
                }

                
            },
            //重填  all重新下注
            resetFun(){
                this.quickBetSel = false;
                this.betSum = '';
                //向父组件发送清空指令
                this.$emit('resetsFun');
            },
            // 清空 快捷下注金额
            clearbetmoneyFun(){
                this.betSum = '';
            },
            contBetFun(item){
                // console.log(item);
                var _this = this;
                if((this.$route.query.id == 2) && this.$route.query.levelid == 18){   //六合彩  连码
                    if(item == '二全中'){
                        var num = 2;
                    }else if(item == '二中特'){
                        var num = 2;
                    }else if(item == '三全中'){
                        var num = 3;
                    }else if(item == '三中二'){
                        var num = 3;
                    }else if(item == '特串'){
                        var num = 2;
                    }else if(item == '四全中'){
                        var num = 4;
                    }else if(item == '选二连组'){
                        var num = 2;
                    }else if(item == '选三连组'){
                        var num = 3;
                    }else if(item == '选三前组'){
                        var num = 3;
                    }else if(item == '选四前组'){
                        var num = 4;
                    }
                }else if((this.$route.query.id == 2) && (this.$route.query.levelid == 12 || this.$route.query.levelid == 19)){   //六合彩  合肖  过关
                    var num = 2;
                }else if((this.$route.query.id == 2) && this.$route.query.levelid == 15){   //六合彩  自选不中
                    var num = 5;
                }else if(this.$route.query.id == 2 && this.$route.query.levelid == 16){  //连肖
                    if(item == '二肖连中' || item == '二肖连不中'){
                        var num = 2;
                    }else if(item == '三肖连中' || item == '三肖连不中'){
                        var num = 3;
                    }else if(item == '四肖连中' || item == '四肖连不中'){
                        var num = 4;
                    }else if(item == '五肖连中' || item == '五肖连不中'){
                        var num = 5;
                    }
                }else if(this.$route.query.id == 2 && this.$route.query.levelid == 17){  //连尾
                    if(item == '二尾连中' || item == '二尾连不中'){
                        var num = 2;
                    }else if(item == '三尾连中' || item == '三尾连不中'){
                        var num = 3;
                    }else if(item == '四尾连中' || item == '四尾连不中'){
                        var num = 4;
                    }else if(item == '五尾连中' || item == '五尾连不中'){
                        var num = 5;
                    }
                }else if((this.$route.query.id == 11 || this.$route.query.id == 12 || this.$route.query.id == 13) && this.$route.query.levelid == 3){  //连码
                    if(item == '任选二'){
                        var num = 2;
                    }else if(item == '任选三'){
                        var num = 3;
                    }else if(item == '任选四'){
                        var num = 4;
                    }else if(item == '任选五'){
                        var num = 5;
                    }else if(item == '任选六'){
                        var num = 6;
                    }else if(item == '任选七'){
                        var num = 7;
                    }else if(item == '任选八'){
                        var num = 8;
                    }else if(item == '前二组选'){
                        var num = 2;
                    }else if(item == '前三组选'){
                        var num = 3;
                    }
                }else if((this.$route.query.id == 11 || this.$route.query.id == 12 || this.$route.query.id == 13) && this.$route.query.levelid == 4){  //直码
                    if(item == '前二直选'){
                        var num = 1;
                    }else if(item == '前三直选'){
                        var num = 1;
                    }
                }else if((this.$route.query.id == 14 || this.$route.query.id == 15) && this.$route.query.levelid == 11){
                    if(item == '任选二'){
                        var num = 2;
                    }else if(item == '选二连组'){
                        var num = 2;
                    }else if(item == '任选三'){
                        var num = 3;
                    }else if(item == '选三前组'){
                        var num = 3;
                    }else if(item == '任选四'){
                        var num = 4;
                    }else if(item == '任选五'){
                        var num = 5;
                    }
                }
                

                if(_this.contBetData.betArr.length < num){
                    alert('至少选择'+ num +'个/组！');
                }else{
                    // console.log('----',_this.contBetData);
                    _this.params = lotterytype.apiParams(_this.$route.query.id,_this.$route.query.levelid);

                    if((this.$route.query.id == 11 || this.$route.query.id == 12 || this.$route.query.id == 13) && this.$route.query.levelid == 4){  //直码  

                        var txt = '';  //下注明细
                        var sum = 0;  //总金额

                        sum = parseInt(_this.contBetData.betArr.length) * parseFloat(_this.betSum);

                        for(var i = 0;i<_this.contBetData.betArr.length;i++){
                            
                            _this.betconfirm.push({'item': _this.contBetData.betArr[i],'rate': _this.contBetData.betnowtype,'money': _this.betSum});
                            txt += '第' + (i+1) + '组    [' + _this.contBetData.betArr[i] + ']  @  ' + _this.contBetData.betnowtype + '  *  ￥' + _this.betSum +'\n';
                        }

                        var mymessage=confirm('共￥'+ sum +' / '+ _this.contBetData.betArr.length +'笔，确认下注吗？\n\n下注明细如下：\n\n' + txt);
                        if(mymessage==true){
                            //下注
                            var arr = [];
                            for(var i = 0;i<_this.contBetData.betArr.length;i++){

                                arr.push({'balls': _this.contBetData.betArr[i].split(','),'item': '选号:'+ item +':$fn','value': _this.betSum});
                            }
                            
                            this.$httpPost('/api/bet/bet',{
                                    'game': _this.params.nowlottery,
                                    'items': arr,
                                }).then(response => {
                                //下注成功（发送   最新注单事件）
                                if(response.status == 200){
                                    _this.$emit('betsuccess',response.data);
                                }

                            });                               
                        }

                    }else if((this.$route.query.id == 2) && (this.$route.query.levelid == 12 || this.$route.query.levelid == 15 || this.$route.query.levelid == 19)){  // 六合彩的合肖、自选不中
                        var txt = '';  //下注明细
                        var sum = 0;  //总金额

                        sum = _this.betSum;
                        if(this.$route.query.levelid == 12){  //合肖
                            if(_this.contBetData.betArr.length == 2){
                                var name = '二肖';
                            }else if(_this.contBetData.betArr.length == 3){
                                var name = '三肖';
                            }else if(_this.contBetData.betArr.length == 4){
                                var name = '四肖';
                            }else if(_this.contBetData.betArr.length == 5){
                                var name = '五肖';
                            }else if(_this.contBetData.betArr.length == 6){
                                var name = '六肖';
                            }else if(_this.contBetData.betArr.length == 7){
                                var name = '七肖';
                            }else if(_this.contBetData.betArr.length == 8){
                                var name = '八肖';
                            }else if(_this.contBetData.betArr.length == 9){
                                var name = '九肖';
                            }else if(_this.contBetData.betArr.length == 10){
                                var name = '十肖';
                            }else if(_this.contBetData.betArr.length == 11){
                                var name = '十一肖';
                            }
                        }else if(this.$route.query.levelid == 15){  //自选不中
                            if(_this.contBetData.betArr.length == 5){
                                var name = '五不中';
                            }else if(_this.contBetData.betArr.length == 6){
                                var name = '六不中';
                            }else if(_this.contBetData.betArr.length == 7){
                                var name = '七不中';
                            }else if(_this.contBetData.betArr.length == 8){
                                var name = '八不中';
                            }else if(_this.contBetData.betArr.length == 9){
                                var name = '九不中';
                            }else if(_this.contBetData.betArr.length == 10){
                                var name = '十不中';
                            }else if(_this.contBetData.betArr.length == 11){
                                var name = '十一不中';
                            }else if(_this.contBetData.betArr.length == 12){
                                var name = '十二不中';
                            }else if(_this.contBetData.betArr.length == 13){
                                var name = '十三不中';
                            }else if(_this.contBetData.betArr.length == 14){
                                var name = '十四不中';
                            }else if(_this.contBetData.betArr.length == 15){
                                var name = '十五不中';
                            }else if(_this.contBetData.betArr.length == 16){
                                var name = '十六不中';
                            }else if(_this.contBetData.betArr.length == 17){
                                var name = '十七不中';
                            }
                        }else if(this.$route.query.levelid == 19){  //过关
                            var name = '过关';
                        }
                        

                        var nowstr = '';
                        for(var i = 0;i<_this.contBetData.betArr.length;i++){
                            
                            nowstr += _this.contBetData.betArr[i] + ',';
                            
                        }

                        txt += name +'    [' + nowstr + ']  @  ' + _this.contBetData.betnowtype.toFixed(2) + '  *  ￥' + _this.betSum +'\n';
                        _this.betconfirm.push({'item': nowstr,'rate': _this.contBetData.betnowtype.toFixed(2),'money': _this.betSum});

                        var mymessage=confirm('共￥'+ sum +' / 1笔，确认下注吗？\n\n下注明细如下：\n\n' + txt);
                        if(mymessage==true){
                            //下注
                            var arr = [];
                            if(this.$route.query.levelid == 12){  //合肖
                                arr.push({'balls': _this.contBetData.betArr,'item': '特码:合肖:'+name,'value': _this.betSum});
                            }else if(this.$route.query.levelid == 15){  //自选不中
                                arr.push({'balls': _this.contBetData.betArr,'item': '七码:自选不中:'+name,'value': _this.betSum});
                            }else if(this.$route.query.levelid == 19){  //过关
                                arr.push({'balls': _this.contBetData.betArr,'item': '正码:'+name+':正一_单','value': _this.betSum});
                            }
                            
                            this.$httpPost('/api/bet/bet',{
                                    'game': _this.params.nowlottery,
                                    'items': arr,
                                }).then(response => {
                        
                                if(response.status == 200){
                                    _this.$emit('betsuccess',response.data);
                                }

                            });                              
                        }
                    }else{

                        this.$httpGet('/api/bet/combine/'+ _this.params.nowlottery + '/' + item,{
                                'balls': _this.contBetData.betArr
                            }).then(response => {
                    
                            if(response.status == 200){
                                var txt = '';  //下注明细
                                var sum = 0;  //总金额

                                sum = parseInt(response.data.length) * parseFloat(_this.betSum);

                                for(var i = 0;i<response.data.length;i++){
                                    
                                    _this.betconfirm.push({'item': response.data[i],'rate': _this.contBetData.betnowtype,'money': _this.betSum});
                                    txt += '第' + (i+1) + '组    [' + response.data[i] + ']  @  ' + _this.contBetData.betnowtype + '  *  ￥' + _this.betSum +'\n';
                                }

                                var mymessage=confirm('共￥'+ sum +' / '+ response.data.length +'笔，确认下注吗？\n\n下注明细如下：\n\n' + txt);
                                if(mymessage==true){
                                    //下注
                                    var arr = [];
                                    
                                    if(_this.$route.query.id == 2 && (_this.$route.query.levelid == 16 || _this.$route.query.levelid == 17)){  //连肖、连尾

                                        for(var i = 0; i< response.data.length; i++){
                                            arr.push({'balls': response.data[i].split(','),'item': '七码:'+ item +':$fn','value': _this.betSum});
                                        }
                                        
                                    }else if((_this.$route.query.id == 11 || _this.$route.query.id == 12 || _this.$route.query.id == 13) && _this.$route.query.levelid == 3){

                                        arr.push({'balls': _this.contBetData.betArr,'item': '选号:'+ item +':$fn','value': _this.betSum});

                                    }else if(((_this.$route.query.id == 14 || _this.$route.query.id == 15) && _this.$route.query.levelid == 11) || (_this.$route.query.id == 2 && _this.$route.query.levelid == 18)){

                                        arr.push({'balls': _this.contBetData.betArr,'item': '连码:'+ item +':$fn','value': _this.betSum});

                                    }
                                    
                                    this.$httpPost('/api/bet/bet',{
                                            'game': _this.params.nowlottery,
                                            'items': arr,
                                        }).then(response => {
                                            //下注成功（发送   最新注单事件）
                                        if(response.status == 200){
                                            _this.$emit('betsuccess',response.data);
                                        }

                                    });                               
                                }
                            }

                        });

                    }

                    
                }
            },
        },
        mounted(){
            this.init();
        },
        watch: {
            quickBetSel: function(now,old){
                
                if(this.quickBetSel && this.betSum != ''){
                    this.$emit('moneyfocusFun',this.betSum);
                }else{
                    this.$emit('moneyfocusFun','');
                }
            },
            betSum: function(now,old){

                if(this.quickBetSel && this.betSum != ''){
                    this.$emit('moneyfocusFun',this.betSum);
                }else{
                    this.$emit('moneyfocusFun','');
                }
            },
            noBet: function(now,old){
                // console.log(now,old);
                //封盘  不可下注
                this.betDisabled = true;
            },
            openBet: function(now,old){
                // console.log(now,old);
                //开奖  可下注
                this.betDisabled = false;
            },

        },
    }
</script>
